package com.holike.crm.fragment.monthdata;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.holike.crm.R;
import com.holike.crm.adapter.AbsFormAdapter;
import com.holike.crm.base.BaseFragment;
import com.holike.crm.bean.MonthDataInstallManagerBean;
import com.holike.crm.helper.TextSpanHelper;

import java.util.List;

/**
 * Created by pony on 2019/8/9.
 * Copyright holike possess 2019.
 * 安装经理本月数据帮助类
 */
class InstallManagerMonthDataHelper extends MonthDataHelper {

    private FrameLayout mContainer;

    InstallManagerMonthDataHelper(BaseFragment<?, ?> fragment, Callback callback) {
        super(fragment, callback);
    }

    void initView() {
        mContainer = mFragmentView.findViewById(R.id.fl_container);
    }

    void onSuccess(MonthDataInstallManagerBean bean) {
        mContainer.removeAllViews();
        View view = LayoutInflater.from(mContext).inflate(R.layout.include_month_data_installmanager_content, mContainer, true);
        TextView tvTime = view.findViewById(R.id.tv_time);
        tvTime.setText(bean.timeData);
        TextView tvInstallArea = view.findViewById(R.id.tv_install_area);
        tvInstallArea.setText(TextSpanHelper.getSquareMeter(tvInstallArea.getText().toString()));
        RecyclerView recyclerView = view.findViewById(R.id.recyclerView);
        ItemContentAdapter adapter = new ItemContentAdapter(mContext, bean.getArr());
        recyclerView.setAdapter(adapter);
    }

    void onFailure(String failReason) {
        mContainer.removeAllViews();
        LayoutInflater.from(mContext).inflate(R.layout.include_empty_page, mContainer, true);
        mFragment.noNetwork(failReason);
    }

    static class ItemContentAdapter extends AbsFormAdapter<MonthDataInstallManagerBean.ArrBean> {

        ItemContentAdapter(Context context, List<MonthDataInstallManagerBean.ArrBean> mDatas) {
            super(context, mDatas);
        }

        @Override
        protected int bindView(int viewType) {
            return R.layout.item_month_data_installmanager_content;
        }

        @Override
        protected void bindViewHolder(RecyclerHolder holder, MonthDataInstallManagerBean.ArrBean bean, int position) {
            holder.setText(R.id.tv_name, bean.name);
            holder.setText(R.id.tv_install_count, bean.installed); //安装数
            holder.setText(R.id.tv_install_area, bean.area);
            holder.setText(R.id.tv_complete_rate, bean.firstSuccess);//一次安装完成率
            holder.setText(R.id.tv_satisfaction, bean.Satisfied);
        }
    }
}
